﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Button1 : BaseButton
{
    protected override void Start()
    {
        base.Start();

        // 订阅事件
        _healthSystem.OnHealthChanged += OnHealthChanged;
    }

    private void OnHealthChanged(int newHealth)//这个地方我没有调用方法，是使用了事件功能
    {
       // Debug.Log($"Health changed to: {newHealth}");
        // 可以在这里添加其他逻辑，例如显示UI更新、播放音效等
    }

    protected override void OnButtonClick()
    {
        base.OnButtonClick();
        //Debug.Log("Button 1 clicked!");
        // 其他特定于按钮1的逻辑
       // OnHealthChanged(1);
        _healthSystem.TakeDamage(1);

    }
    public HealthSystem _healthSystem;
    // Update is called once per frame
    void Update()
    {

    }
    void OnDestroy()
    {
        // 退订事件，防止内存泄漏
        _healthSystem.OnHealthChanged -= OnHealthChanged;
    }
}

